<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>yanbo</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="{{url('admin/css/font.css')}}">
    <link rel="stylesheet" href="{{url('admin/css/xadmin.css')}}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="{{url('admin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{ url('admin/js/xadmin.js') }}"></script>
    <script type="text/javascript" src="{{url('admin/js/cookie.js')}}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">报考信息管理</a>
        <a href="">报考专业</a>
        <a>
          <cite>专业信息</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <xblock>
{{--                                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--}}
                        <button class="layui-btn" onclick="xadmin.open('添加','{{ route('projects.create') }}')"><i class="layui-icon"></i>增加顶级目录</button>
                        <span  align="right" class="x-right" style="line-height:40px">共有数据：{{$count}} 条</span>
                    </xblock>
                    <hr>
                </div>

                <table class="layui-table layui-form">
                    <thead>
                    <tr>
                        <th width="20">
                            {{--                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>--}}
                            <input type="checkbox" name="" lay-skin="primary">

                        </th>
                        <th width="70">ID</th>
                        <th>栏目名</th>
                        {{--            <th width="50">排序</th>--}}
                        <th width="50">状态</th>
                        <th width="250">操作</th>
                    </thead>
                    <tbody class="x-cate">

                    @foreach($msg as $key=>$val)

                        {{--    顶层 p_id=0        最外层--}}
                        <tr cate-id='{{ $val['id'] }}' fid='{{$val['pid']}}' >
                            <td>
                                {{--                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>--}}
                                <input type="checkbox" name="" lay-skin="primary">

                            </td>
                            <td>{{ $val['id'] }}</td>
                            <td>
                                <i class="layui-icon x-show" status='true'>&#xe623;</i>

                                {{$val['name']}}
                            </td>
                            {{--                        <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                            <td>
                                @if($val['status']==1)
                                    <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                @else
                                    <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                @endif

                            </td>
                            <td class="td-manage">

                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('添加','{{route('create.son.project',$val['id'])}}')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$val['id']}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                            </td>
                        </tr>


                        {{--               去除没有2级分类的顶级栏目--}}
                        @if(!empty($val['son']) )
                            {{--    内部 p_id > 0   第2层     --}}
                            @foreach($val['son'] as $son_key=>$son_val)

                                @if( empty($son_val['son']))
                                    <tr cate-id='{{ $son_val['id'] }}' fid='{{$son_val['pid']}}' >
                                        <td>
                                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
                                        </td>
                                        <td>{{ $son_val['id'] }}</td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;
                                            ├{{$son_val['name']}}
                                        </td>
                                        {{--                        <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                                        <td>
                                            @if($val['status']==1)
                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                            @else
                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                            @endif
                                        </td>
                                        <td class="td-manage">
                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$son_val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                            <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('添加','{{route('create.son.project',$son_val['id'])}}')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                            <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{ $son_val['id'] }}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                            <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                                        </td>
                                    </tr>
                                @else
                                    <tr cate-id='{{ $son_val['id'] }}' fid='{{$son_val['pid']}}' >
                                        <td>
                                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
                                        </td>
                                        <td>{{ $son_val['id'] }}</td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;
                                            <i class="layui-icon x-show" status='true'>&#xe623;</i>{{$son_val['name']}}
                                        </td>
                                        {{--                            <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                                        <td>
                                            @if($val['status']==1)
                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                            @else
                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                            @endif
                                        </td>
                                        <td class="td-manage">
                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$son_val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                            <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('编辑','{{route('create.son.project',$son_val['id'])}}')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                            <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{ $son_val['id'] }}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                            <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                                        </td>
                                    </tr>


                                    {{--    内部 p_id > 0   第3层     --}}
                                    @foreach($son_val['son'] as $three_key=>$three_val)

                                        @if( empty($three_val['son']))
                                            <tr cate-id='{{ $three_val['id'] }}' fid='{{$three_val['pid']}}' >
                                                <td>
                                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
                                                </td>
                                                <td>{{ $three_val['id'] }}</td>
                                                <td>
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    ├{{$three_val['name']}}
                                                </td>
                                                {{--                                    <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                                                <td>
                                                    @if($val['status']==1)
                                                        <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                                    @else
                                                        <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                                    @endif
                                                </td>
                                                <td class="td-manage">

                                                    <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$three_val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                                    <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('编辑','admin-edit.html')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                                    <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$three_val['id']}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                                    <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                                                </td>
                                            </tr>
                                        @else
                                            <tr cate-id='{{ $three_val['id'] }}' fid='{{$three_val['pid']}}' >
                                                <td>
                                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
                                                </td>
                                                <td>{{ $three_val['id'] }}</td>
                                                <td>
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <i class="layui-icon x-show" status='true'>&#xe623;</i>{{$three_val['name']}}
                                                </td>
                                                {{--                                        <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                                                <td>
                                                    @if($val['status']==1)
                                                        <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                                    @else
                                                        <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                                    @endif
                                                </td>
                                                <td class="td-manage">
                                                    <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$three_val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                                    <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('编辑','{{route('create.son.project',$three_val['id'])}}')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                                    <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$three_val['id']}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                                    <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                                                </td>
                                            </tr>


                                            {{--    内部 p_id > 0   第4层     --}}
                                            @foreach($three_val['son'] as $four_key=>$four_val)

                                                @if( empty($four_val['son']))
                                                    <tr cate-id='{{ $four_val['id'] }}' fid='{{$four_val['pid']}}' >
                                                        <td>
                                                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
                                                        </td>
                                                        <td>{{ $four_val['id'] }}</td>
                                                        <td>
                                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                            ├{{$four_val['name']}}
                                                        </td>
                                                        {{--                                                <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                                                        <td>
                                                            @if($val['status']==1)
                                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                                            @else
                                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                                            @endif
                                                        </td>
                                                        <td class="td-manage">
                                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$four_val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                                            <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('编辑','{{route('create.son.project',$four_val['id'])}}')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                                            <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$four_val['id']}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                                            <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                                                        </td>
                                                    </tr>
                                                @else
                                                    <tr cate-id='{{ $four_val['id'] }}' fid='{{$four_val['pid']}}' >
                                                        <td>
                                                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
                                                        </td>
                                                        <td>{{ $four_val['id'] }}</td>
                                                        <td>
                                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                            <i class="layui-icon x-show" status='true'>&#xe623;</i>{{$four_val['name']}}
                                                        </td>
                                                        {{--                                                <td><input type="text" class="layui-input x-sort" name="order" value="1"></td>--}}
                                                        <td>
                                                            @if($val['status']==1)
                                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID" checked="" lay-skin="switch">
                                                            @else
                                                                <input type="checkbox" name="switch"  lay-text="开启|停用"  value="{{ $val['id'] }}" lay-filter="switchGoodsID"  lay-skin="switch">
                                                            @endif
                                                        </td>
                                                        <td class="td-manage">

                                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','{{route('projects.edit',$four_val['id'] )}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                                            <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('编辑','admin-edit.html')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                                            <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$four_val['id']}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                                            <input class="_token" name="_token" type="hidden" value="{{ csrf_token() }}">
                                                        </td>
                                                    </tr>
                                                @endif
                                            @endforeach

                                        @endif
                                    @endforeach

                                @endif

                            @endforeach

                        @endif

                    @endforeach

                    </tbody>
                </table>
{{--                <div class="layui-card-body ">--}}
{{--                    <div class="page">--}}
{{--                        <div>--}}
{{--                            <a class="prev" href="">&lt;&lt;</a>--}}
{{--                            <a class="num" href="">1</a>--}}
{{--                            <span class="current">2</span>--}}
{{--                            <a class="num" href="">3</a>--}}
{{--                            <a class="num" href="">489</a>--}}
{{--                            <a class="next" href="">&gt;&gt;</a></div>--}}
{{--                    </div>--}}
{{--                </div>--}}
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function(){
        form = layui.form;

    });

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据

            var taken = $(obj).next("input").val();


            $.ajax({
                headers : {
                    // 'Accept' : 'text/javascript',
                    'Content-Type' : 'application/x-www-form-urlencoded',
                    'X-CSRF-TOKEN':taken
                },
                data:{
                    id:id,
                },
                url:'{{route('delete.project')}}',
                type:'post',
                success:function (res) {

                    console.log(res.status);

                    if (res.status == 'success'){

                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else{
                        // $(obj).parents("tr").remove();
                        layer.msg(res.message,{icon:2,time:2000});
                    }


                },error:function (res) {

                    // alert(JSON.stringify(res)
                    // var datas = JSON.stringify(res);
                    // alert(res);
                    console.log(res);


                }
            });
        });
    }



    // 分类展开收起的分类的逻辑
    //
    $(function(){
        $("tbody.x-cate tr[fid!='0']").hide();
        // 栏目多级显示效果
        $('.x-show').click(function () {
            if($(this).attr('status')=='true'){
                $(this).html('&#xe625;');
                $(this).attr('status','false');
                cateId = $(this).parents('tr').attr('cate-id');
                $("tbody tr[fid="+cateId+"]").show();
            }else{
                cateIds = [];
                $(this).html('&#xe623;');
                $(this).attr('status','true');
                cateId = $(this).parents('tr').attr('cate-id');
                getCateId(cateId);
                for (var i in cateIds) {
                    $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                }
            }
        })
    })

    var cateIds = [];
    function getCateId(cateId) {
        $("tbody tr[fid="+cateId+"]").each(function(index, el) {
            id = $(el).attr('cate-id');
            cateIds.push(id);
            getCateId(id);
        });
    }

</script>
</body>
</html>

